#include<bits/stdc++.h>
#define F(i,x,y) for (int i=(x);i<=(y);i++)
#define R(i,x,y) for (int i=(x);i>=(y);i--)
#define p2i pair<int,int>
#define ll long long
#define fi first
#define se second
#define pub push_back
#define ins insert
#define puf push_front
#define vec vector
#define umap unordered_map
#define uset unordered_set
#define popf pop_front
#define popb pop_back
#define nb(x) (1<<((x)-1))
#define x1 __melody1
#define x2 __melody2
#define y1 __melody3
#define y2 __melody4
#define iosoptim ios::sync_with_stdio(0);cin.tie(0);
using namespace std;

const bool MT = 0;
const int N=5e5+5,SK=1e6+5;
int n,c,b[N],dt[SK],dcnt;
ll ans[SK];
vector<int> tg[N],sg[SK];
unordered_map<int,int> bc; 
vector<int> res; // hack umap bhe maa chut
void solve(){
	// Insert your code here
    cin>>n;
    int tmp,k;
    F(i,1,n) {
        cin>>k;
        while (k--) {
            cin>>tmp;
            tg[i].push_back(tmp);
        }
    }
    cin>>c;
    F(i,1,n) cin>>b[i];
    // Initialize
    F(i,1,n) {
        for (int j:tg[i]) {
            if (!bc.count(j)) bc[j]=0;
            bc[j]++;
        }
        F(j,1,tg[i].size()-1) {
            dt[++dcnt]=tg[i][j]-tg[i][j-1];
        }
    }
    sort(dt+1,dt+dcnt+1); dcnt=unique(dt+1,dt+dcnt+1)-dt-1;
    F(i,1,n) {
        F(j,1,tg[i].size()-1) {
            // for a segment with length j, its contribution matters in x=j+1
            int ulen=lower_bound(dt+1,dt+dcnt+1,tg[i][j]-tg[i][j-1])-dt;
            sg[ulen].push_back(tg[i][j]);
        }
    }
    // Calculate the answer when x=1
    int acnt=0;
    ll nasum=0,bsum=0;
    F(i,1,n) acnt+=tg[i].size();
    for (auto i:bc) {
        bsum+=1ll*i.se*b[i.se];
    }
    ans[0]=1ll*c*acnt+bsum;
    ll mi=ans[0];
    F(i,1,dcnt) {
        // Suppose when x=dt[i]+1
        for (int j:sg[i]) {
            // Segment will be deactivated
            acnt--;
            nasum+=1ll*dt[i]*c;
            bc[j]--;
            bsum-=1ll*(bc[j]+1)*b[bc[j]+1];
            bsum+=1ll*bc[j]*b[bc[j]];
        }
        ans[i]=1ll*c*acnt*(dt[i]+1)+nasum+bsum;
        mi=min(mi,ans[i]);
    }
    F(i,0,dcnt) {
        if (ans[i]==mi) res.push_back(dt[i]+1);
    }
    cout<<mi<<" "<<res.size()<<"\n";
    for (int i:res) cout<<i<<" ";
    cout<<"\n";
}
void cleanup() {

}
int main (){
    freopen("list.in","r",stdin);
    freopen("list.out","w",stdout);
    iosoptim
	int testcases=1;
	if(MT) cin>>testcases;
	while(testcases--){
		solve();
		cleanup();
	}
	return 0;
}
